<template>
  <div class="container-header">
    <!-- 左侧 -->
    <div class="header-left">
      <img class="left-img" src="@/assets/logo.png" />
      <div class="left-title">{{ title }}</div>
    </div>
    <div class="right-content">
      <!-- 中间目录 -->
      <div class="header-center">
        <div class="center-trigon"></div>
        <div v-for="(item, index) in menuList" :class="[
          'menu-list-item',
          'center-menu',
          curId == item.id ? 'active' : '',
        ]" :key="index" @click="changeMenu(item)">
          <span class="menu-title"> {{ item.label }} </span>
        </div>
        <!-- <div class="center-trigon"></div> -->
      </div>
      <!-- 右侧部分 -->
      <div class="header-right">
        <div>
          标准时间:<span class="right-time">{{ time }}</span>
        </div>
        <div class="admin-span">
          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              <span class="iconfont icon-yonghu"></span>
              管理员
              <span class="iconfont icon-xiala"></span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <span @click="personalCenter">
                  <el-dropdown-item class="padding">个人中心</el-dropdown-item>
                </span>
                <span @click="goBackHome">
                  <el-dropdown-item class="Center">退出</el-dropdown-item>
                </span>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </div>

  </div>
</template>
<script lang="ts">
import {
  reactive,
  onBeforeMount,
  onMounted,
  toRefs,
  getCurrentInstance,
} from "vue";
import store from "@/store";

export default {
  props: {
    menuList: {
      type: Array,
      default() {
        return [];
      },
    },
    // 标题
    title: {
      type: String,
      default: "场景编辑器",
    },
    // 是否展示菜单
    showMenu: {
      type: Boolean,
      default: true,
    },
    // 是否可设置
    showConfig: {
      type: Boolean,
      default: true,
    },
  },
  setup(props, { emit }) {
    const {
      appContext: {
        config: { globalProperties },
      },
    } = getCurrentInstance() as any;
    const state = reactive({
      isFullscreen: true,
      time: "",
      date: "",
      curId: "",
      loginTitle: "admin",
      show: true,
    });
    onBeforeMount(() => {
      isTime();
    });
    onMounted(() => {
      let topMenu: any = localStorage.getItem("topMenu");
      if (topMenu && globalProperties.$route.name != "home") {
        state.curId = JSON.parse(topMenu).id;
      } else {
        changeMenu(props.menuList[0]);
        //  globalProperties.$router.push({ path: props.menuList[0].path, query: {} });
      }
    });
    // 跳转到主页
    const toHome = () => {
      // console.log("home");
      globalProperties.$router.push("/home");
    };
    const fullScreen = () => {
      if (state.isFullscreen) {
        globalProperties.$utils.screenFullEnter();
      } else {
        globalProperties.$utils.screenFullOut();
      }

      state.isFullscreen = !state.isFullscreen;
    };
    //去主页
    const goHome = () => {
      let urlAddress = `http://${window.location.host}/tj/admin/`;
      location.href = urlAddress;
      // this.$router.push("/");
    };
    // 计时器
    const isTime = () => {
      // let time = setInterval(() => {
      //   _this.time = _this.$utils.formatDate(new Date(), 2);
      // }, 1000);
      state.time = globalProperties.$utils.formatDate(new Date(), 2);
      state.date = globalProperties.$utils.formatDate(new Date(), 1);

      setInterval(() => {
        state.time = globalProperties.$utils.formatDate(new Date(), 2);
        state.date = globalProperties.$utils.formatDate(new Date(), 1);
      }, 1000);
      console.log(state.time);
    };
    const changeMenu = (item: any) => {
      // if (item.name == "QB数据服务") {
      //   window.open(this.iframeURL);
      //   return;
      // }
      // console.log(item,'item')
      emit("changeMenu", item);
      // globalProperties.$router.push({ path: item.path, query: {} });
      state.curId = item.id;
    };
    // 个人中心
    const personalCenter = () => {
      emit("personalCenter");
    };
    // 退出
    const goBackHome = () => {
      store.commit("REMOVE_INFO");
      globalProperties.$router.push("/login");
      emit("goBackHome");
    };
    return {
      ...toRefs(state),
      goHome,
      isTime,
      fullScreen,
      changeMenu,
      toHome,
      personalCenter,
      goBackHome,
    };
  },
};
</script>

<style scoped lang="less">
.active {
  // background: linear-gradient(to bottom, #05f385 40%, #0d0dcf 80%) !important;
  // -webkit-text-fill-color: transparent !important;
  // -webkit-background-clip: text !important;
  // font-weight: 700 !important;
  color: #0764f1;
}

.iconfont {
  color: #fff;
  font-size: 24px;
}

.icon-yonghu {
  margin-right: 8px;
  font-size: 26px;
}

.container-header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  align-items: center;
  color: @main-font-color;
  // border-bottom: 1px solid @global-border-color;
  background-color: @global-border-color;
  display: flex;

  .header-left {
    width: 400px;
    height: 100%;
    font-size: 23px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-sizing: border-box;
    padding: 0 30px;
    background: url("../assets/image/header_bg.png") no-repeat;
    // background-repeat: no-repeat;
    background-size: 100% 100%;

    // background-position: center;
    .left-img {
      width: 35px;
    }
  }

  .right-content {
    flex: 1;
    display: flex;
    height: 100%;
    box-sizing: border-box;

    // padding: 5px 0;
    // border-bottom: 2px solid rgb(13, 117, 235);
    // 	border-image: radial-gradient(rgb(246, 247, 248) 30%, rgb(16, 88, 241) 160%) 10;
    .header-center {
      width: 75%;
      height: 100%;
      display: flex;
      overflow: hidden;

      .menu-list-item {
        font-size: 23px;
        // background: linear-gradient(to bottom, white 40%, blue 80%);
        // -webkit-text-fill-color: transparent;
        // -webkit-background-clip: text;
        // font-weight: 700;
      }

      .center-menu {
        width: calc(100% - 160px);
        display: flex;
        justify-content: space-around;
        background: #02457a;
      }

      .center-trigon {
        width: 130px;
        height: 90px;
        background: #02457a;
        transform: translate(14px, -5px) rotate(23deg);
        //   width:0;
        //   height:0;
        //   // border: none;
        //   border-left: 80px solid rgba(0,0,0,0);
        //   border-top: 80px solid rgba(0,0,0,0);
        //   border-right: 80px solid #02457a;
        //   border-bottom: 80px solid #02457a;
      }
    }

    .header-right {
      flex: 1;
      height: 100%;
      font-size: 18px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #02457a;

      .right-time {
        color: #008fc9;
        margin-left: 8px;
      }

      .admin-span {
        height: 100%;
        // width: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-left: 15px;

        .title-style {
          padding-left: 5px;
        }

        .el-dropdown-link {
          height: 100%;
          display: flex;
          align-items: center;
          color: #fff;
        }

        .icon-wang {
          margin-right: 8px;
        }
      }

      :deep(.el-dropdown-menu) {
        // padding: 5px 20px;
        padding: 0;
      }
    }
  }

  //   .header-center::before{
  //      content: "";
  //     position: absolute;
  //     top: -2px;
  //     left: -2px;
  //     right: -2px;
  //     bottom: -2px;
  //     background:#fff;
  //     z-index: -1;
  //   }
  //   .header-center ::after{
  //      content: "";
  //     position: absolute;
  //     top: -2px;
  //     left: -2px;
  //     right: -2px;
  //     bottom: -2px;
  //     background:#fff;
  //     z-index: -2;
  //     filter:blur(20px)
  //   }
  //   .header-center:before,.header-center:after{
  //     background: linear-gradient(235deg,#89ff00,#060c21,#00bcd4);
  // }


}

.menu-list {
  align-items: center;
  justify-content: space-around;
  flex: 1;
  height: 100%;
  // justify-content: space-around;
  margin-left: 100px;

  &-item {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    font-size: @header-item-size;
    cursor: pointer;
  }
}
</style>
